package com.gemme.gemme.shequ;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;

import com.gemme.gemme.R;
import com.gemme.gemme.SearchActivity;
import com.gemme.gemme.fragment.BaseLazyFragment;
import com.gemme.gemme.home.HomeNewFragment;
import com.gemme.gemme.view.DefineLoadMoreView;
import com.gemme.gemme.view.GuanzhuHeadView;
import com.gemme.gemme.view.StaggeredDividerItemDecoration;
import com.yanzhenjie.recyclerview.OnItemClickListener;
import com.yanzhenjie.recyclerview.SwipeRecyclerView;

import java.util.ArrayList;
import java.util.List;


/**
 * Created by sp on 2019/7/18.
 * 首页
 */
public class GuanzhuFragment extends BaseLazyFragment  {

    View inflate;
    Context mContext;
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        inflate = inflater.inflate(R.layout.fragment_guanzhu, container, false);

        mContext = GuanzhuFragment.this.getContext();

        initView(inflate);
        return inflate;
    }


    private SwipeRefreshLayout mRefreshLayout;
    private SwipeRecyclerView mRecyclerView;
    private List<String> mDataList;
    StaggeredDividerItemDecoration staggeredDividerItemDecoration;
    private void initView(View inflate) {
        setList(inflate);

    }

    private void setList(View inflate) {
        mRefreshLayout = inflate.findViewById(R.id.refresh_layout);
        mRecyclerView = inflate.findViewById(R.id.recycler_view);

        mRecyclerView.addHeaderView(new GuanzhuHeadView(mContext));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mContext));

        /*StaggeredGridLayoutManager layoutManager = new
                StaggeredGridLayoutManager(2, StaggeredGridLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(layoutManager);

        if(staggeredDividerItemDecoration == null){
            staggeredDividerItemDecoration = new StaggeredDividerItemDecoration
                    (mContext, (int) getResources().getDimension(R.dimen.dp_11));
            mRecyclerView.addItemDecoration(staggeredDividerItemDecoration);
        }*/

        DefineLoadMoreView loadMoreView = new DefineLoadMoreView(mContext);
        mRecyclerView.addFooterView(loadMoreView); // 添加为Footer。
        mRecyclerView.setLoadMoreView(loadMoreView); // 设置LoadMoreView更新监听。
        mRefreshLayout.setOnRefreshListener(mRefreshListener); // 刷新监听。
        mRecyclerView.setLoadMoreListener(mLoadMoreListener); // 加载更多的监听。

        mRefreshLayout.setEnabled(false);
        mRecyclerView.setAdapter(new GuanZhuAdapter());
    }

    /**
     * 加载更多。
     */
    private SwipeRecyclerView.LoadMoreListener mLoadMoreListener = new SwipeRecyclerView.LoadMoreListener() {
        @Override
        public void onLoadMore() {

        }
    };

    /**
     * 刷新。
     */
    private SwipeRefreshLayout.OnRefreshListener mRefreshListener = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {

        }
    };

    /**
     * Item点击监听。
     */
    private OnItemClickListener mItemClickListener = new OnItemClickListener() {
        @Override
        public void onItemClick(View itemView, int position) {
            Toast.makeText(mContext, "第" + position + "个", Toast.LENGTH_SHORT).show();
        }
    };


     class GuanZhuAdapter extends RecyclerView.Adapter<GuanZhuAdapter.ViewHolder>{

         @NonNull
         @Override
         public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
             View inflate = LayoutInflater.from(parent.getContext()).
                     inflate(R.layout.item_guanzhu, null);
             LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
             inflate.setLayoutParams(layoutParams);
             return new GuanZhuAdapter.ViewHolder(inflate);
         }

         @Override
         public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

         }

         @Override
         public int getItemCount() {
             return 14;
         }

         public class ViewHolder extends RecyclerView.ViewHolder {
             public ViewHolder(@NonNull View itemView) {
                 super(itemView);
             }
         }
     }



    @Override
    public void onLazyLoad() {

        //yc

//        getData();
    }









}
